Back to Main Menu

Asset Spatial Search

Assetic Python SDK sample

The following code sample uses the AsseticPython SDK to perform same search as in the payload example shown in the Asset Spatial Search article on the integration section. Please refer to the article for a more general overview of how to perform an Asset Spatial Search.

 

  1. """
  2. Get assets by sptaial search (Assetic.AssetsGetByPoint.py)
  3. """
  4. import assetic
  5. #Assetic SDK instance
  6. asseticsdk=assetic.AsseticSDK("c:/users/you/assetic.ini",None,"Debug")
  7. #asset API
  8. assetapi = assetic.AssetApi()
  9. def main():
  10. """
  11. Initiate the search. Search parameters hardcoded here
  12. """
  13. ##get some nearby assets
  14. latitude = -37.7189464838113
  15. longitude = 144.73930864699
  16. nearby = get_assets_by_spatial(latitude,longitude,50,"meter")
  17. for row in nearby:
  18. msg = "Nearby asset {0}, Category {1}".format(
  19. row["properties"]["Asset Name"],row["properties"]["Asset Category"])
  20. asseticsdk.logger.info(msg)
  21. def get_assets_by_spatial(latitude,longitude,radius,uom):
  22. """
  23. Get nearby assets based on a goegraphic point and radius
  24. :param latitude: latitude of point
  25. :param longitude: longitude of point
  26. :param radius: search radius
  27. :param uom: radius unit of measure - meter or kilometer
  28. :return: asset array
  29. """
  30. asseticsdk.logger.info("Get the assets near point {0},{1}".format(
  31. latitude, longitude))
  32. kw = {"request_params_longitude":longitude,
  33. "request_params_latitude":latitude,
  34. "request_params_condition":"near_point",
  35. "request_params_range":radius,
  36. "request_params_unit":uom,
  37. "request_params_page":1,
  38. "request_params_page_size": 500}
  39. try:
  40. assets = assetapi.asset_search_asset_spatial_locations(**kw)
  41. except assetic.rest.ApiException as e:
  42. msg = "Status {0}, Reason: {1} {2}".format(e.status,e.reason,e.body)
  43. asseticsdk.logger.error(msg)
  44. return []
  45. if assets["TotalResults"] > 0:
  46. return assets["ResourceList"][0]["Data"]["features"]
  47. else:
  48. return []
  49. return assets
  50. ##This will run the method main() to kickstart it all
  51. if __name__ == "__main__":
  52. main()